// AutoFiller.h: interface for the CAutoFiller class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_AUTOFILLER_H__879B4E73_241E_450E_81C9_34699AA87CAC__INCLUDED_)
#define AFX_AUTOFILLER_H__879B4E73_241E_450E_81C9_34699AA87CAC__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Point.h"

/// to check whether a point be in range or not
class CCheckInContour
{
public:
	CCheckInContour();
	~CCheckInContour();

public:
	int setMaxSize(int cx, int cy);
	int setContour(const SPoint *lpPoint, int nPoint);
	BOOL inContour(int x, int y);
	int freeMemory(void);
	int getContour(const SPoint **ppPoint);
	int getMaxX(void) const
	{	return m_nMaxX;	}
	int getMaxY(void) const
	{	return m_nMaxY;	}

protected:
	/// x range, in [0, m_nMaxX);
	int		m_nMaxX;
	/// y range, in [0, m_nMaxY);
	int		m_nMaxY;
	/// contour lines, in polygon
	const SPoint	*m_pContour;
	/// count of m_pContour
	int		m_nContour;

protected:
	/// (1, dy) is the selected direction
	int		m_dy;
	/// flag for in contour or not
	BYTE	*m_pInFlag;

protected:
	BOOL initContourCheck(void);
	BOOL checkPointInContour(int x, int y);

protected:
	CCheckInContour(const CCheckInContour&);
	CCheckInContour& operator=(const CCheckInContour&);
};

/// callback to check whether a given point is in range or not
typedef BOOL (CALLBACK *LPCheckInRange)(void *lpContext, int x, int y);

//// a simple filler
class CAutoFiller
{
public:
	CAutoFiller(CCheckInContour *pCheck, BOOL fCircleFill);
	~CAutoFiller();

public:
	BOOL resetGetPoint(int x, int y);
	BOOL getNextPoint(SPoint *lpPoint, LPCheckInRange lpfnCheck, void *lpContext);
	int clear(void);

public:
	inline BOOL inContour(int x, int y)
	{	return m_pCheck->inContour(x, y);	};
	inline int getMaxX(void) const
	{	return m_pCheck->getMaxX();	}
	inline int getMaxY(void) const
	{	return m_pCheck->getMaxY();	}
	inline CCheckInContour* getChecker(void)
	{	return m_pCheck;	};

protected:
	/// helper object to check whether a point in contour or not
	CCheckInContour	*m_pCheck;
	/// point to be checked in filling
	CShortPoint	m_ptChkList;
	/// flag for point being filled or not(the simplest filling)
	BYTE	*m_pbFlag;
	/// count of m_pbFlag
	int		m_nFlag;

protected:
    const SPoint    *m_pOffset;
    int     m_nOffset;
    
protected:
	BOOL addNeighborPoints(const SPoint& pt0, LPCheckInRange lpfnCheck, void *lpContext);

protected:
	CAutoFiller(const CAutoFiller&);
	CAutoFiller& operator=(const CAutoFiller&);
};

#endif // !defined(AFX_AUTOFILLER_H__879B4E73_241E_450E_81C9_34699AA87CAC__INCLUDED_)
